# coding=utf-8
#


"""
发送通知邮件
"""


from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


# 邮件通知配置信息
## 发送邮件相关配置
## QQ邮箱smtp服务器地址
HOST_SERVER = "smtp.qq.com"

## 发件人信息
SENDER_QQ = "2269529891"
SENDER_QQ_MAIL = "2269529891@qq.com"

## qq邮箱的授权码
MAIL_PASSWORD = "somqgettzemreacj"

## 收件人
RECEIVER = ["2269529891@qq.com", "448207223@qq.com"]


def send_mail(title: str, content: str, receivers: list = [], format: str = "text"):
    """
        发送邮件模块

        Args:
            :params: title(str): 邮件标题
            :params: content(str): 正文信息
            :params: receivers(list): 收件人列表

        Returns:
            None
    """

    # 开始发送邮件
    # 邮件正文
    receivers = receivers or RECEIVER

    #邮件标题
    mail_title = title

    #ssl登录
    smtp = SMTP_SSL(HOST_SERVER)
    #smtp.set_debuglevel(1)
    smtp.ehlo(HOST_SERVER)
    smtp.login(SENDER_QQ, MAIL_PASSWORD)

    if format == "html":
        msg = MIMEMultipart()
    else:
        msg = MIMEText(content, "plain", 'utf-8')

    msg["Subject"] = Header(mail_title, 'utf-8')
    msg["From"] = SENDER_QQ_MAIL
    msg["To"] = ",".join(receivers)

    if format == "html":
        msg.attach(MIMEText(content, "html", "utf-8"))
    smtp.sendmail(SENDER_QQ_MAIL, receivers, msg.as_string())
    smtp.quit()
